package com.msmall.community.play.action.html;

import com.msmall.base.action.HTMLBaseAction;
import com.msmall.base.util.ConstantAjax;
import com.msmall.community.play.model.Play;
import com.msmall.community.play.service.PlayManager;

public class PlayAction extends HTMLBaseAction {

	private static final long serialVersionUID = 8334761066954812940L;
	
	private Long playId;
	
	private Play play;
	
	private PlayManager playManager;

	public void setPlayManager(PlayManager playManager) {
		this.playManager = playManager;
	}
	
	public String execute(){
		page.setPageSize(15);
		try {
			playManager.getAvaliablePlays(page);
		} catch (Exception e) {
		}
		return SUCCESS;
	}
	
	public String add(){
		StringBuffer buffer = new StringBuffer();
		buffer.append(ConstantAjax.RETURN_PRE);
		try {
			boolean tag = playManager.joinPlay(getUserid(), playId);
			if(tag){
				buffer.append(ConstantAjax.RESULT_TRUE);
			}else{
				buffer.append(ConstantAjax.RESULT_FALSE)
				.append(ConstantAjax.CONTENT_PRE)
				.append(getText("sys.play.error.already"))
				.append(ConstantAjax.CONTENT_SUFF);
			}
		} catch (Exception e) {
			buffer.append(ConstantAjax.RESULT_FALSE)
			.append(ConstantAjax.CONTENT_PRE)
			.append(getText("sys.play.error"))
			.append(ConstantAjax.CONTENT_SUFF);
		}
		buffer.append(ConstantAjax.RETURN_SUFF);
		super.setMessage(buffer.toString());
		return SUCCESS;
	}
	
	public String view(){
		try {
			play = playManager.getPlay(playId);
		} catch (Exception e) {
			return SUCCESS;
		}
		return SUCCESS;
	}

	public Long getPlayId() {
		return playId;
	}

	public void setPlayId(Long playId) {
		this.playId = playId;
	}

	public Play getPlay() {
		return play;
	}

	public void setPlay(Play play) {
		this.play = play;
	}
	
}
